package com.yj.timecapsule.controller.user;
import com.yj.timecapsule.common.response.CommonResponseType;
import com.yj.timecapsule.entity.user.dto.UserLoginDto;
import com.yj.timecapsule.entity.user.vo.FriendsVo;
import com.yj.timecapsule.entity.user.vo.UserLoginVo;
import com.yj.timecapsule.entity.user.vo.UserSearchVO;
import com.yj.timecapsule.entity.user.vo.UserVo;
import com.yj.timecapsule.service.user.UserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;
    @PostMapping("/login")
    public CommonResponseType<UserLoginVo> login(@RequestBody UserLoginDto dto){
        UserLoginVo vo = userService.login(dto);
        return CommonResponseType.success(vo);
    }

    @GetMapping("/get-info")
    public CommonResponseType<UserVo> getInfo(){
        UserVo vo = userService.getUserDetail();
        return CommonResponseType.success(vo);
    }

    @PutMapping("/set-background-image")
    public CommonResponseType<Object> setBackgroundImage(@RequestParam("image") String image){
        userService.setBackgroundImage(image);
        return CommonResponseType.success();
    }
    @PutMapping("/set-avatar")
    public CommonResponseType<Object> setAvatar(@RequestParam("avatar") String avatar){
        userService.setAvatar(avatar);
        return CommonResponseType.success();
    }
    @GetMapping("/get-friend-list")
    public CommonResponseType<List<FriendsVo>> getFriendList(){
        List<FriendsVo> friendsVoList = userService.getFriendList();
        return CommonResponseType.success(friendsVoList);
    }
    @GetMapping("/get-friend-request")
    public CommonResponseType<Map<String,Object>> getFriendRequest(){
        Map<String,Object> result = userService.getFriendRequest();
        return CommonResponseType.success(result);
    }
    @PostMapping("/request-friend")
    public CommonResponseType<Object> requestFriend(@RequestParam("receiverId") Long receiverId){
        userService.requestFriend(receiverId);
        return CommonResponseType.success();
    }
    @PostMapping("/agree-friend-request")
    public CommonResponseType<Object> agreeFriendRequest(@RequestParam("senderId") Long senderId){
        userService.agreeFriendRequest(senderId);
        return CommonResponseType.success();
    }
    @DeleteMapping("/del-friend")
    public CommonResponseType<Object> delFriend(@RequestParam("friendId") Long friendId){
        userService.delFriend(friendId);
        return CommonResponseType.success();
    }
    @GetMapping("/search")
    public CommonResponseType<List<UserSearchVO>> search(@RequestParam(required = false,value = "keyWord") String keyWord,@RequestParam(required = false,value = "phone") String phone){
        List<UserSearchVO> searchVOList = userService.search(keyWord,phone);
        return CommonResponseType.success(searchVOList);
    }
    @PutMapping("/rejected-friend-request")
    public CommonResponseType<Object> rejectedFriendRequest(@RequestParam("senderId") Long senderId){
        userService.rejectedFriendRequest(senderId);
        return CommonResponseType.success();
    }


    

}
